<?php

require_once dirname(__FILE__).'/../lib/unidad_formacionGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/unidad_formacionGeneratorHelper.class.php';

/**
 * unidad_formacion actions.
 *
 * @package    sistema_itec_new
 * @subpackage unidad_formacion
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class unidad_formacionActions extends autoUnidad_formacionActions
{
    
    function executeAjaxNew(sfWebRequest $request) {
        $form = new unidadFormacionForm();
        $module = $this->getModuleName();
        
        if($request->isMethod(sfRequest::POST)) {
            $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
            if($form->isValid()) {
                $object = $form->save();
                
                return $this->renderText('SUCCESS. [id:'.$object->getid().'][nombre:'.$object.'][model:'.$module.']');
            }
        }
        
        $title = 'Nueva '.ucwords(str_replace('_', ' ', $module));
        $backend_route = sfConfig::get('app_backend_route');
        $html = <<<EOF
            <form method="post" action="/$backend_route/$module/AjaxNew">
                <h2>$title</h2>
                <div class="box">
                    $form
                </div>
EOF;
        return $this->renderText($html);
    }
    
}
